using System;
using System.Windows;
using System.Windows.Controls.Primitives;

namespace FireStarterModeller.UI.DetailsView.WPF
{
    /// <summary>
    /// Interaction logic for RenameItemPopup.xaml
    /// </summary>
    public partial class RenameItemPopup : Popup
    {
        private object _itemToRename;
        public event EventHandler OKButtonClicked;

        public RenameItemPopup()
        {
            InitializeComponent();
        }

        public object ItemToRename
        {
            get { return _itemToRename; }
        }

        public string NewName
        {
            get { return _renameTextBox.Text; }
        }


        private void _renameButton_Click(object sender, RoutedEventArgs e)
        {
            FireOKButtonClicked();
        }

        private void FireOKButtonClicked()
        {
            if (OKButtonClicked != null) OKButtonClicked(this, new EventArgs());
        }

        public void Init(object itemToRename, string itemType, string itemName)
        {
            _itemToRename = itemToRename;
            _renameLabel.Content = string.Format("Rename {0} {1} to...", itemType, itemName);
            _renameTextBox.Text = itemName;
        }

        private void Popup_Opened(object sender, EventArgs e)
        {
            _renameTextBox.Focus();
            _renameTextBox.SelectAll();
        }
    }
}